package personal.zq.practice.common.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

@Slf4j
public class DesensitizationUtil {

    private DesensitizationUtil() {
    }

    /**
     * 姓名加*
     *
     * @param name
     * @return
     */
    public static String nameDesensitization(String name) {
        if (StringUtils.isEmpty(name)) {
            return "";
        }
        return name.replaceAll("(.+)(.)$", "*$2");
    }

    /**
     * 身份证加*
     *
     * @param cardId
     * @return
     */
    public static String cardIdDesensitization(String cardId) {
        if (StringUtils.isEmpty(cardId)) {
            return "";
        }
        return cardId.replaceAll("^(\\d)(\\w{0,16})(\\w)$", "$1****$3");
    }
}
